/*
 * auiutils.cpp
 *
 *  Created on: Jul 13, 2012
 *      Author: Yangde
 */

#include "wx/wxprec.h"

#include "wx/dc.h"
#include "./auiutils.h"

wxAuiUtils *wxAuiUtils::__uinstance=NULL;

wxAuiUtils::wxAuiUtils(){
		m_base_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
		m_bt_highlight_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT);
		m_bt_shadow_colour  = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW);

		m_border_colour = m_bt_shadow_colour;

	    if ((255-m_base_colour.Red()) +
	        (255-m_base_colour.Green()) +
	        (255-m_base_colour.Blue()) < 60)
	    {
	    	m_base_colour = m_base_colour.ChangeLightness(92);
	    }


	    m_menu_highlight_border_colour = wxColour(60,122,180);
	    m_menu_highlight_top_colour = wxColour(84,151,214);
	    m_menu_highlight_bot_colour = wxColour(71,140,205);


	    m_highlightColour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
	    m_highlightTextColour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);

	    menu_font = *wxNORMAL_FONT;
	    menu_font.SetUnderlined(false);

	    menu_font_u = menu_font;
	    menu_font_u.SetUnderlined(true);
	}


void wxAuiUtils::DrawToolBar(
       wxDC& dc,
       const wxRect& _rect
       ,int type)
{
	wxRect rect = _rect;
	if(type)
	{
		dc.GradientFillLinear(rect, m_base_colour.ChangeLightness(110), m_base_colour.ChangeLightness(98), wxSOUTH);


		dc.SetPen(wxPen(m_base_colour.ChangeLightness(160)));
		dc.DrawLine(rect.x, rect.y, rect.x+rect.width, rect.y);

		dc.SetPen(wxPen(m_base_colour.ChangeLightness(75)));
		dc.DrawLine(rect.x, rect.y+rect.height-1, rect.x+rect.width, rect.y+rect.height-1);

		if(type&4)
		{
			wxRect r = _rect;
			r.height=5;
			dc.GradientFillLinear(r, m_base_colour.ChangeLightness(126), m_base_colour.ChangeLightness(108), wxSOUTH);
		}


		if(type&1)
		{
			wxRect r = _rect;
			r.height=3;
			r.y += (_rect.height-3);
			dc.GradientFillLinear(r, m_base_colour.ChangeLightness(98), m_base_colour.ChangeLightness(90), wxSOUTH);
		}

	}
	else
	{
		dc.SetPen(wxPen(m_base_colour));
		dc.SetBrush(wxBrush(m_base_colour));
		dc.DrawRectangle(rect);
	}
}

void wxAuiUtils::DrawMenuText(const wxString &text,
       wxDC& dc,
       int sx,int sy
       ,int u_index)
{

	dc.SetFont(menu_font);
	dc.DrawText(text,sx,sy);

	if(u_index>=0 &&u_index<text.Length())
	{
		dc.SetFont(menu_font_u);
		wxString s = text.substr(0,u_index);
		int x,y;
		dc.GetTextExtent(s,&x,&y);
		sx+=x;
		s = text.substr(u_index,1);
		dc.DrawText(s,sx,sy);
	}

}

void wxAuiUtils::DrawMenuHighlight(
       wxDC& dc,
       wxRect &rect)
{
	dc.GradientFillLinear(rect,m_menu_highlight_top_colour,m_menu_highlight_bot_colour,wxSOUTH);
	dc.SetPen(wxPen(m_menu_highlight_border_colour));
	dc.SetBrush(*wxTRANSPARENT_BRUSH);
	dc.DrawRectangle(rect);
}

void wxAuiUtils::Draw3DBorder(
       wxDC& dc,
       const  wxRect& rect,
       const wxColour& highlight_color,
       const wxColour& shadow_color)
{
	dc.SetPen(wxPen(highlight_color));
	dc.DrawLine(rect.x,rect.y,rect.x+rect.width,rect.y);
	dc.DrawLine(rect.x,rect.y,rect.x,rect.y+rect.height);
	dc.SetPen(wxPen(shadow_color));
	dc.DrawLine(rect.x           ,rect.y+rect.height-1,rect.x+rect.width,rect.y+rect.height-1  );
	dc.DrawLine(rect.x+rect.width-1,rect.y            ,rect.x+rect.width-1  ,rect.y+rect.height);
}
